Page({

    data:{
        time:'',
        id:'',
        url:''
    },

    btn01:function(e){
        let temperature = (Math.random()*(33-15)+15).toFixed(2)+'摄氏度'
        wx.showModal({
            title:'温度',
            content:temperature,
            showCancel:false
        })

        wx.cloud.database().collection('user_temp').add({
            data:{
                time:this.getDate(),
                wendu:temperature,
            }
        })
    },
    btn02:function(e){
        let humidity = (Math.random()*(80-30)+30).toFixed(0)+'%'
        wx.showModal({
            title:'湿度',
            content:humidity,
            showCancel:false
        })
        wx.cloud.database().collection('user_hum').add({
            data:{
                time:this.getDate(),
                shidu:humidity,
            }
        })
    },
    btn03:function(e){
        let oxygen = (Math.random()*(23-21)+21).toFixed(1)+'%'
        wx.showModal({
            title:'氧含量',
            content:oxygen,
            showCancel:false
        })
        wx.cloud.database().collection('user_oxygen').add({
            data:{
                time:this.getDate(),
                yhl:oxygen,
            }
        })
    },
        getDate(){
        var date = new Date();
           var year = date.getFullYear();    //  返回的是年份
           var month = date.getMonth() + 1;  //  返回的月份上个月的月份，记得+1才是当月
           var dates = date.getDate();       //  返回的是几号
           var hours = date.getHours();
           var minutes = date.getMinutes();
           var seconds = date.getSeconds()
           var day = date.getDay();          //  周一返回的是1，周六是6，但是周日是0
           var arr = [ "星期日","星期一","星期二","星期三","星期四","星期五","星期六",];
           return  year + "年" + month + "月" + dates + "日" + hours+ "时" + minutes + "分" + seconds+"秒" +arr[day]
        
       },
       onShow(){
           setInterval(()=>{
            this.setData({
                time:this.getDate()
           })
           },1000)
           
       },
       onLoad(options) {
        console.log(options);
        this.setData({
            id:options.id,
            url:options.url
        })
    }


})
